home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / eev100r1.zip / INFIX.DOC < prev    next >
Text File  |  1993-04-01  |  5KB  |  134 lines

  1.   ------------------------------------------------------------------------
  2.   INFIX.PAS
  3.   ------------------------------------------------------------------------
  4.  
  5.     This unit uses recursive descent to evaluate expressions
  6.     written in infix notation.  The operations addition (+),
  7.     subtraction (-), multiplication (*), and division (/) are supported,
  8.     as are the functions ABS, ARCTAN, COS, EXP, LN, SQR, and SQRT.
  9.     PI returns the value for pi.  Results exceeding 1.0E37 are reported
  10.     as overflows.  Results less than 1.0E-37 are set to zero.
  11.  
  12.          Written by:
  13.  
  14.          James L. Dean
  15.          406 40th Street
  16.          New Orleans, LA 70124
  17.          February 25, 1985
  18.  
  19.          Modified by:
  20.  
  21.          David J. Firth
  22.          5665-A2 Parkville St.
  23.          Columbus, OH 43229
  24.          December 26, 1991
  25.  
  26.      This code was originally written as a stand-alone program using
  27.      standard Pascal.  In that form the program wasn't very useful.
  28.      I have taken the code and reorganized it for use with Turbo Pascal
  29.      versions 5.x or 6.0.  I have added six procedures to this code
  30.      for use as an API (application program interface).  Those six
  31.      routines are described in this file.
  32.  
  33.      In addition, I have reworked it to support variables by adding a
  34.      preprocessor.  The variables are preceded and followed by a @ symbol,
  35.      are case sensitive, and must be less than 20 characters long
  36.      (including the 2 @s). For example, the following would all be valid
  37.      variables:
  38.  
  39.      @VARIABLE1@      @Pressure3@      @AngleOfAttack@
  40.  
  41.      Variable identifiers are passed around as strings of type Str20.
  42.  
  43.      The variable-related procedures are:
  44.  
  45.      -------------------------------------------------------------------
  46.  
  47.      procedure StoreVariable(VariableID:str20;MyValue:real);
  48.  
  49.      This procedure will store MyValue in the variable identified by
  50.      VariableID.  If the variable doesn't exist, it will be created.
  51.      If the variable does exist, the value will be updated.
  52.  
  53.      -------------------------------------------------------------------
  54.  
  55.      procedure ReadVariable(VariableID:str20;var MyValue:real;
  56.                             var MyError:boolean);
  57.  
  58.      This procedure will read the value of the variable identified by
  59.      VariableID.  If the variable doesn't exist, MyError will be true.
  60.  
  61.      -------------------------------------------------------------------
  62.  
  63.      procedure DestroyList;
  64.  
  65.      The variables are stored in a singly linked list.  If your program
  66.      uses variables, you need to call this routine before you exit to
  67.      DOS.  Otherwise, the memory taken by the linked list will not be
  68.      given back.
  69.  
  70.      -------------------------------------------------------------------
  71.  
  72.      Calculation results may either be stored in variables or returned
  73.      to the caller.  The following procedures should be used to call
  74.      the expression evaluator.
  75.  
  76.      -------------------------------------------------------------------
  77.  
  78.      procedure RawCalculate(MyFormula:string;var MyResult:real;
  79.                             var MyError:byte);
  80.  
  81.      This procedure will evaluate an expression that does not contain
  82.      variables.  This procedure calls the original code.  It has been
  83.      superceded by Calculate and CalcAndStore.
  84.  
  85.      MyError=0 indentifies a successful evaluation.  A non-zero
  86.      value holds the offset of the error in the formula.
  87.  
  88.      -------------------------------------------------------------------
  89.  
  90.      procedure Calculate(MyFormula:string;var MyResult:real;var MyError:byte);
  91.  
  92.      This procedure will evaluate an expression containing zero or
  93.      more variables.  The result is returned to the caller.
  94.  
  95.      MyError=0 indentifies a successful evaluation.  A non-zero
  96.      value holds the offset of the error in the formula.  However,
  97.      the error is the offset of the error in the formula AFTER the
  98.      variable's ID strings have been replaced with the numeric
  99.      values.
  100.  
  101.      Calculate calls RawCalculate for final expression evaluation.
  102.  
  103.      -------------------------------------------------------------------
  104.  
  105.      procedure CalcAndStore(MyFormula:string;StoreID:str20;var MyError:byte);
  106.  
  107.      This procedure will evaluate an expression containing zero or
  108.      more variables.  The result is stored in the variable indentified
  109.      by StoreID.
  110.  
  111.      MyError=0 indentifies a successful evaluation.  A non-zero
  112.      value holds the offset of the error in the formula.  However,
  113.      the error is the offset of the error in the formula AFTER the
  114.      variable's ID strings have been replaced with the numeric
  115.      values.
  116.  
  117.      CalcAndStore calls Calculate for expression evaluation.
  118.  
  119.      -------------------------------------------------------------------
  120.  
  121.      Unfortunately, the original code is virtually unreadable due
  122.      to the original author's lack of any comments.  I have attempted
  123.      to provide a front end to this code that is useful and understandable.
  124.  
  125.      I have tested this code using Turbo Debugger 2.0 and it seems
  126.      to work fine.  However, if you find a bug, please let me know.
  127.  
  128.      Your comments are welcome (and desired!). My E-Mail addresses
  129.      are:
  130.  
  131.      GEnie:     D.FIRTH
  132.      CIS:       76467,1734
  133.  
  134.